<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row type="flex">
          <a-col>
            <a-button icon="plus" style="margin-right: 20px" type="primary" @click="openAdd()">新增</a-button>
            <a-divider style="margin-right: 20px" type="vertical" />
          </a-col>
          <a-col :md="5" :sm="7" style="margin-left: 15px">
            <a-form-item label="年份">
              <a-select v-model="queryParam.year" placeholder="请选择年份">
                <a-select-option v-for="(i,index) in yearList" :key="index" :value="i.key">{{ i.name }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="7" style="margin-left: 15px">
            <a-form-item label="地区">
              <a-select v-model="queryParam.areaName" placeholder="请选择地区">
                <a-select-option v-for="(i,index) in selectList" :key="index" :value="i.key">{{ i.name }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col flex="auto" style="margin-left: 15px">
            <span class="table-page-search-submitButtons" style="float: left; overflow: hidden;margin-right: 20px">
              <a-button icon="search" style="margin-left: 10px" type="primary" @click="searchQuery">查询</a-button>
              <a-popover :overlayStyle="{background: 'white'}" placement="topLeft">
                <template slot="content">
                  <a-icon theme="twoTone" two-tone-color="#52c41a" type="exclamation-circle" /><span
                  style="margin-left: 5px">可以点击重置来重新筛选结果</span>
                </template>
                <a-button
                  icon="reload"
                  style="margin-left: 8px"
                  @click="searchReset"
                >重置</a-button>
              </a-popover>

            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 操作按钮区域 -->
    <div class="table-operator">
    </div>
    <div>
      <a-table
        ref="table"
        :columns="columns"
        :dataSource="dataSource"
        :loading="loading"
        :pagination="ipagination"
        bordered
        rowKey="id"
        size="middle"
        @change="handleTableChange">
        <span slot="type" slot-scope="text, record">
          <a-tag v-if="text == '0'" color="red">国内</a-tag>
          <a-tag v-if="text == '1'" color="blue">国际</a-tag>
        </span>
        <span slot="action" slot-scope="text, record">
          <a-button style="margin-right: 10px" type="primary" @click="handleEdit(record)">
            编辑
          </a-button>
            <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
              <a-button>
                删除
              </a-button>
            </a-popconfirm>
        </span>
      </a-table>
      <map-data-modal ref="modalForm" @ok="modalFormOk"></map-data-modal>
    </div>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import pick from 'lodash.pick'
import { getAction } from '@api/manage'
import MapDataModal from '@views/dataVisualization/components/mapDataModal'

const date = new Date()
const count = date.getFullYear() - 2020
const yearlist = []
for (let i = 0; i < count + 1; i++) {
  yearlist.push({
    name: date.getFullYear() - i,
    key: date.getFullYear() - i
  })
}

export default {
  name: 'mapData',
  components: { MapDataModal },
  mixins: [JeecgListMixin],
  data() {
    return {
      queryParam: {
        year: '2022'
      },
      selectList: [
        { name: '黄浦区', key: '黄浦区' },
        { name: '徐汇区', key: '徐汇区' },
        { name: '长宁区', key: '长宁区' },
        { name: '静安区', key: '静安区' },
        { name: '普陀区', key: '普陀区' },
        { name: '虹口区', key: '虹口区' },
        { name: '杨浦区', key: '杨浦区' },
        { name: '闵行区', key: '闵行区' },
        { name: '宝山区', key: '宝山区' },
        { name: '嘉定区', key: '嘉定区' },
        { name: '浦东新区', key: '浦东新区' },
        { name: '金山区', key: '金山区' },
        { name: '松江区', key: '松江区' },
        { name: '青浦区', key: '青浦区' },
        { name: '奉贤区', key: '奉贤区' },
        { name: '崇明区', key: '崇明区' }
      ],
      yearList: yearlist,
      confirmLoading: false,
      title: '',
      visible: false,
      dataSource: [],
      form: this.$form.createForm(this),
      dialogStyle: {
        top: '200px'
        // right:"20px",
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      columns: [
        {
          title: '地区',
          align: 'center',
          dataIndex: 'areaName',
          width: 120
        },
        {
          title: '年份',
          align: 'center',
          dataIndex: 'year',
          width: 120
        },
        {
          title: '能源消费总量(10⁴tce)',
          align: 'center',
          dataIndex: 'totalEnergyConsumption',
          width: 200
        },
        {
          title: '预测能源消费总量(10⁴tce)',
          align: 'center',
          dataIndex: 'totalEnergyConsumptionYc',
          width: 200
        },
        {
          title: '碳排放总量(10⁴tco²)',
          align: 'center',
          dataIndex: 'totalCarbonEmissions',
          width: 200
        },

        {
          title: '预测碳排放总量(10⁴tco²)',
          align: 'center',
          dataIndex: 'totalCarbonEmissionsYc',
          width: 200
        },
        {
          title: '分数',
          align: 'center',
          dataIndex: 'mark',
          width: 120
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/carbon/carbonOverviewYearData/list',
        delete: '/carbon/carbonOverviewYearData/delete'
      }
    }
  },
  created() {
  },
  mounted() {
    // this.getData()
  },
  methods: {

    // getData() {
    //   getAction('/carbon/carbonOverviewYearData/getDataByYearArea?year=' + '2022', {}).then((res) => {
    //     if (res.success) {
    //       console.log(res.result)
    //       this.dataSource = res.result
    //       // this.model = res.result.records[0]
    //       this.$nextTick(() => {
    //         this.form.setFieldsValue(pick(
    //           this.model,
    //           'areaName',
    //           // 'year',
    //           // 'totalEnergyConsumption',
    //           // 'totalEnergyConsumptionYoy',
    //           // 'totalCarbonEmissions',
    //           // 'totalCarbonEmissionsYoy',
    //           // 'energyConsumptionIntensity',
    //           // 'energyConsumptionIntensityYoy',
    //           // 'carbonEmissionIntensity',
    //           // 'carbonEmissionIntensityYoy'
    //         ))
    //       })
    //     }
    //   })
    // },
    openAdd() {
      this.$refs.modalForm.add()
      this.$refs.modalForm.title = '新增'
      this.$refs.modalForm.disableSubmit = false
    }
  }
}
</script>

<style scoped>

</style>